local AddonName, SMQ = ...;
local _G = _G;

-- The options for SMQueue
function SMQ:CreateDB()
	return { profile = {
		MarkTank = true,
		FlashScreen = true,
		PartyIntro = true,
		PartyIntroText = "Hello!",
		PartyGoodbye = true,
		PartyGoodbyeText = "Thx for group! :D",
		LeaveAfterLoot = true,
		SoundAlarm = true,
		SelectedLDBQueue = 1, -- Defaults to LFG timer displaying
		ShowActive = true,
		--AutoSelect = true,
		--ShowBuiltIn = true,
		WaitTimeMode = true,
	}};
end

-- The configuration table
local function CreateConfig()
	return {
		type = "group",
		name = AddonName,
		order = 1,
		get = function(info)
			return SMQ.db[info[#info]];
		end,
		set = function(info, value)
			SMQ.db[info[#info]] = value;
		end,
		args = {
			configdesc2 = {
				name = "About",
				type = "group", inline = true,
				order = 0,
				get = function(info)
					return SMQ.db[info[#info]];
				end,
				set = function(info, value)
					SMQ.db[info[#info]] = value;
				end,
				args = {
					configversiondesc = {
						order = 1,
						type = "description",
						name = "Version: "..GetAddOnMetadata("SMQueue", "Version"),
						cmdHidden = true
					},
					configauthordesc = {
						order = 2,
						type = "description",
						name = "Author: "..GetAddOnMetadata("SMQueue", "Author"),
						cmdHidden = true
					},
					configemaildesc = {
						order = 3,
						type = "description",
						name = "Email: rice_cakes@lavabit.com",
						cmdHidden = true
					},
					configlicdesc = {
						order = 4,
						type = "description",
						name = "License: GNU Public License",
						cmdHidden = true
					},
				}
			},
			configoptdesc = {
				name = "Options",
				type = "group", inline = true,
				order = 1,
				get = function(info)
					return SMQ.db[info[#info]];
				end,
				set = function(info, value)
					SMQ.db[info[#info]] = value;
				end,
				args = {
					SelectedLDBQueue = {
						order = 5,
						name = "Selected Queue",
						desc = "Selects the queue to display time elasped/wait time for LDB text.",
						type = "select",
						values = {
							[1] = "Dungeon Finder",
							[3] = "Raid Finder",
							[4] = "Scenarios",
							[5] = "Pet Battles",
							[6] = "Player Vs. Player",
						},
						get = function(info)
							return SMQ.db.SelectedLDBQueue;
						end,
						set = function(info, value)
							SMQ.db.SelectedLDBQueue = value;
							SMQ:UpdateBroker();
						end,
					},
					MarkTank = {
						order = 6,
						name = "Mark Tank",
						desc = "Marks the Tank when joining a new dungeon group (or party members change).",
						type = "toggle",
					},
					FlashScreen = {
						order = 7,
						name = "Flash Screen",
						desc = "Flashes screen when a LFD/LFR proposal is shown.",
						type = "toggle",
					},
					SoundAlarm = {
						order = 8,
						name = "Sound Alarm",
						desc = "Sounds the alarm when your LFD/LFR proposal is shown.",
						type = "toggle",
					},
					LeaveAfterLoot = {
						order = 9,
						name = "Leave After Loot",
						desc = "Fires confirmation pop-up after loot to automatically leave dungeon/raid.",
						type = "toggle",
					},
					WaitTimeMode = {
						order = 10,
						name = "Wait Time Mode",
						desc = "Shows the time waited / approx. wait time in LDB text. Otherwise, shows roles with green/red status.",
						type = "toggle",
					},
					--AutoSelect = {
						--order = 10,
						--name = "Auto-Select Queue",
						--desc = "Automatically select the queues to be displayed, when only waiting in ONE queue. Also, only show the active queues, when cycling thru with left-click.",
						--type = "toggle",
					--},
					--ShowActive = {
						--order = 11,
						--name = "Show Only Active Queues",
						--desc = "When cycling through queues, only show those that are active.",
						--type = "toggle",
					--},
					ShowBuiltIn = {
						order = 12,
						name = "Show Blizzard Tooltips",
						desc = "When queued, show Blizzard's built-in tooltips.",
						type = "toggle",
					},
				},
			},
			configoptintro = {
				name = "Introduction",
				type = "group", inline = true,
				order = 2,
				args = {
					PartyIntro = {
						order = 13,
						name = "Party Intro",
						desc = "Send an introduction to party/raid members when entering dungeon/raid.",
						type = "toggle",
					},
					PartyIntroText = {
						order = 14,
						name = "Party Intro Text",
						desc = "Chat message to be sent if Party Intro option is enabled.",
						type = "input",
						width = "full",
					},
				},
			},
			configoptgoodbye = {
				name = "Goodbye",
				type = "group", inline = true,
				order = 3,
				get = function(info)
					return SMQ.db[info[#info]];
				end,
				set = function(info, value)
					SMQ.db[info[#info]] = value;
				end,
				args = {
					PartyGoodbye = {
						order = 12,
						name = "Party Goodbye",
						desc = "Send a goodbye to party/raid members when leaving dungeon/raid.",
						type = "toggle",
					},
					PartyGoodbyeText = {
						order = 13,
						name = "Party Goodbye Text",
						desc = "Chat message to be sent if Party Goodbye option is enabled.",
						type = "input",
						width = "full",
					},
				},
			},
		}		
	};
end

function SMQ:OpenOptions()
	_G.InterfaceOptionsFrame_OpenToCategory(AddonName);
end

LibStub("AceConfig-3.0"):RegisterOptionsTable(AddonName, CreateConfig);
LibStub("AceConfigDialog-3.0"):AddToBlizOptions(AddonName);
_G.SlashCmdList["SMQUEUE"] = SMQ.OpenOptions;
_G["SLASH_SMQUEUE1"] = "/smq";